<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">网站设置 <small>所有网站设置</small></h3>
            <?php echo breadcrumb(array('网站设置', 'advert/grid'=>'广告管理', '编辑广告')); ?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-plus-sign"></i>编辑广告</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                	<form class="form-horizontal line-form" action="<?php echo base_url('advert/editPost') ?>" method="post" enctype="multipart/form-data">
                        <div class="control-group">
                            <label class="control-label"><em>* </em>展示位置</label>
                            <div class="controls">
                            	<input type="hidden" name="id" value="<?php echo $advert->id; ?>">
                                <select name="position" class="medium m-wrap valid">
                                    <?php foreach ($advertArray as $key=>$value) : ?>
                                        <option value="<?php echo $key;?>" <?php if ($advert->position == $key):?>selected="selected"<?php endif ?>><?php echo $value; ?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>标题</label>
                            <div class="controls">
                                <input type="text" name="title" class="m-wrap large required" value="<?php echo $advert->title;?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>跳转类型</label>
                            <div class="controls">
                                <select name="opentype" class="medium m-wrap valid">
                                        <option value="<?php echo $advert->opentype;?>"><?php echo $advert->opentype;?></option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>打开参数</label>
                            <div class="controls">
                                <input type="text" class="m-wrap large required" name="openvar" value="<?php echo $advert->openvar;?>"/> 
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>图片</label>
                            <div class="controls">
                                <div class="file-image" style="width: 120px;height: 120px;float: left;">
                                    <img src="<?php echo $this->config->show_image_url($advert->picture)?>" width=110 height="100">
                                </div>
                                <input type="file" name="picture">
                                <input type="hidden" name="picture" value="<?php echo $advert->picture;?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>供应商UID</label>
                            <div class="controls">
                                <input type="text" class="m-wrap large number required" name="provider_id" value="<?php echo $advert->provider_id;?>"/> 
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>排序</label>
                            <div class="controls">
                                <input type="text" class="m-wrap large required number" value="100" name="sort" value="<?php echo $advert->sort;?>"/> 
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit"><i class="icon-ok"></i> 保存</button>
                            <a href="<?php echo base_url('advert/grid') ?>">
                                <button class="btn" type="button">返回</button>
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
    $('.form-horizontal').on('change', 'input[type=file]', function (e) {
        var $this = $(this);
        upLoadImg(e.currentTarget.files[0], function (obj) {
            console.log(obj);
            $this.siblings('[type=hidden]').val(obj.save_path);
            $this.siblings('.file-image').children('img').attr('src', obj.file_url);
        });
    });
</script>
